package net.oschina.app.adapter.me.collectadapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.base.Global;
import net.oschina.app.bean2.CollectBean;
import net.oschina.app.ui.activity.DetailActivity;

import java.util.List;

/**
 * Created by Shinelon on 2017/1/15.
 */

public class CollectCodeListAdapter extends BaseListAdapter<List<CollectBean.FavoriteBean>> {
    private String mUrl;
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(Global.mContext).inflate(R.layout.item_me_collect_common,parent,false);
        CollectCodeHolder holder = new CollectCodeHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CollectBean.FavoriteBean data = (CollectBean.FavoriteBean) mList.get(position);
        ((CollectCodeHolder)holder).tv.setText(data.getTitle());
        mUrl = data.getUrl();
    }

    class CollectCodeHolder extends RecyclerView.ViewHolder{
        public TextView tv;
        public CollectCodeHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv_collect_content);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Global.mContext, DetailActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("url",mUrl);
                    Global.mContext.startActivity(intent);
                }
            });
        }
    }
}
